﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using CardReader;

namespace TestControls {
  public partial class Form1 : Form {

    private BindingList<DateTest> list = new BindingList<DateTest>( );
    DateTest current = new DateTest( );

    public Form1( ) {
      InitializeComponent( );
      this.nullDateTimePicker1.DataBindings.Add( new Binding( "Value", this.bindingSource1, "DateIn", true ) );
      this.nullDateTimePicker2.DataBindings.Add( new Binding( "Value", this.bindingSource1, "DateOut", true ) );
      this.nullDateTimePicker3.DataBindings.Add( new Binding( "Value", this.bindingSource1, "Birthday", true ) );
    
      bindingSource1.DataSource = typeof( DateTest );
      bindingNavigator1.BindingSource = bindingSource1;
    }

    private void Form1_Load( object sender, EventArgs e ) {
      list.Add( new DateTest( null, DateTime.Now.AddDays( -15 ), null ) );
      list.Add( new DateTest( null, DateTime.Now.AddDays( -10 ), null ) );
      list.Add( new DateTest( null, DateTime.Now.AddDays( -5 ), null ) );
      list.Add( new DateTest( null, DateTime.Now.AddDays( -1 ), null ) );
     
      
      
      bindingSource1.DataSource = list;
      bindingSource1.ResetBindings( false );
      current = (DateTest) bindingSource1.Current;
    }


    private void button1_Click( object sender, EventArgs e ) {
      if ( bindingSource1.Current != null ) {
        Debug.WriteLine( ( ( DateTest ) bindingSource1.Current ).HasChanged.ToString( ) );
        Debug.WriteLine( "DateIn : " + ( ( DateTest ) bindingSource1.Current ).DateIn.ToString( ) );
      
      }
    }

    private void button2_Click( object sender, EventArgs e ) {
      foreach ( DateTest item in list ) {
        item.HasChanged = false;
      }
    }

    private void bindingNavigatorMoveNextItem_Click( object sender, EventArgs e ) {
      if ( bindingSource1.Current != null ) {
        Debug.WriteLine( "------------------------" );
        Debug.WriteLine(  current.HasChanged.ToString( ) );
        Debug.WriteLine( "DateIn : " + current.DateIn.ToString( ) );
        Debug.WriteLine( "DateOut : " + ( ( DateTest ) bindingSource1.Current ).DateOut.ToString( ) );
        Debug.WriteLine( "Birthday : " + ( ( DateTest ) bindingSource1.Current ).Birthday.ToString( ) );
      }
    }

    private void nullDateTimePicker3_Validating( object sender, CancelEventArgs e ) {
    
    }

    private void button1_Click_1( object sender, EventArgs e ) {
      BasicCardData data = Reader.ReadCard( );
    }



  }
}
